﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DLLPC.Utilities;

namespace VisionCore
{
    public class IOMap_RTC
    {
        #region 本地端数据
        public string L_ExcSTWaferID { get; set; } = "";
        public string L_SortSTWaferID { get; set; } = "";
        public string L_SortNGSTWaferID { get; set; } = "";
        public string L_RecipeID { get; set; } = "";
        public string L_OperatorName { get; set; } = "";
        public string L_LotNumber { get; set; } = "";
        public string L_CCD1_StartTime { get; set; } = "";
        public string L_CCD2_StartTime { get; set; } = "";

        /// <summary>
        /// 基板上die总行数
        /// </summary>
        public int L_StripRowTotal { get; set; } = 0;
        /// <summary>
        /// 基板上die总列数
        /// </summary>
        public int L_StripColTotal { get; set; } = 0;
        /// <summary>
        /// LotID
        /// </summary>
        public string L_LotId { get; set; } = "";
        /// <summary>
        /// Die长度
        /// </summary>
        public double L_DieLength { get; set; } =0;
        /// <summary>
        /// Die宽度
        /// </summary>
        public double L_DieWhith { get; set; } = 0;
        /// <summary>
        /// Die间距X
        /// </summary>
        public double L_StepSize_X { get; set; } = 0;
        /// <summary>
        /// Die间距Y
        /// </summary>
        public double L_StepSize_Y { get; set; } = 0;
        /// <summary>
        /// CCD1_X轴当前位置
        /// </summary>
        public double L_CCD1_CurPos_X{ get; set; } = 0;
        /// <summary>
        /// CCD1_Y轴当前位置
        /// </summary>
        public double L_CCD1_CurPos_Y { get; set; } = 0;
        /// <summary>
        /// CCD1_Z轴当前位置
        /// </summary>
        public double L_CCD1_CurPos_Z { get; set; } = 0;
        /// <summary>
        /// CCD2_X轴当前位置
        /// </summary>
        public double L_CCD2_CurPos_X { get; set; } = 0;
        /// <summary>
        /// CCD2_Y轴当前位置
        /// </summary>
        public double L_CCD2_CurPos_Y { get; set; } = 0;
        /// <summary>
        /// CCD2_Z轴当前位置
        /// </summary>
        public double L_CCD2_CurPos_Z { get; set; } = 0;

        /// <summary>
        /// CCD1拍照总行数
        /// </summary>
        public int L_CCD1_Photo_RowCount { get; set; } = 1;
        /// <summary>
        /// CCD1拍照总列数
        /// </summary>
        public int L_CCD1_Photo_ColCount { get; set; } = 1;
        /// <summary>
        /// CCD1拍照当前行数
        /// </summary>
        public int L_CCD1_Photo_CurrentRow { get; set; } = 1;
        /// <summary>
        /// CCD1拍照当前列数
        /// </summary>
        public int L_CCD1_Photo_CurrentCol { get; set; } = 1;
        /// <summary>
        ///CCD1 拍照Index:0.对位 1.检测 
        /// </summary>
        public int L_CCD1_FuncIndex { get; set; } = 0;
        /// <summary>
        /// CCD1 基板是否镜像
        /// </summary>
        public int L_CCD1_IsMirror { get; set; } = 0;
        /// <summary>
        /// CCD1开始检测时间
        /// </summary>
        public string L_CCD1_InspStartTime { get; set; } = "";
        /// <summary>
        /// CCD1检测通道选择 1-CH1 2-CH2
        /// </summary>
        public int L_CCD1_InspSelect { get; set; } = 1;

        /// <summary>
        /// CCD拍照总行数
        /// </summary>
        public int L_CCD2_Photo_RowCount { get; set; } = 1;
        /// <summary>
        /// CCD2拍照总列数
        /// </summary>
        public int L_CCD2_Photo_ColCount { get; set; } = 1;
        /// <summary>
        /// CCD2拍照当前行数
        /// </summary>
        public int L_CCD2_Photo_CurrentRow { get; set; } = 1;
        /// <summary>
        /// CCD2拍照当前列数
        /// </summary>
        public int L_CCD2_Photo_CurrentCol { get; set; } = 1;
        /// <summary>
        ///CCD2 拍照Index:0.对位 1.检测 
        /// </summary>
        public int L_CCD2_FuncIndex { get; set; } = 0;
        /// <summary>
        /// CCD2 基板是否镜像
        /// </summary>
        public int L_CCD2_IsMirror { get; set; } = 0;
        /// <summary>
        /// CCD2开始检测时间
        /// </summary>
        public string L_CCD2_InspStartTime { get; set; } = "";
        /// <summary>
        /// CCD2检测通道选择 1-CH1 2-CH2
        /// </summary>
        public int L_CCD2_InspSelect { get; set; } = 1;

        #region  OLD

        /// <summary>
        /// 机台状态 1.自动 2.手动 3.报警
        /// </summary>
        public int L_MotionStatus { get; set; } = 0;
        /// <summary>
        /// 拔膜载台拍照行总数
        /// </summary>
        public int L_ExcSTRowCount { get; set; } = 1; 
        /// <summary>
        /// 拔膜载台拍照列总数
        /// </summary>
        public int L_ExcSTColCount { get; set; } = 1;
        /// <summary>
        /// 拔膜载台拍照行总数
        /// </summary>
        public int L_ExcSTCurrentRow { get; set; } = 1;
        /// <summary>
        /// 拔膜载台拍照列总数
        /// </summary>
        public int L_ExcSTCurrentCol { get; set; } = 1;
        /// <summary>
        /// 拍照Index:0.读码 1.拔膜前初对位 2.拔模后检查 
        /// </summary>
        public int L_ExcSTFuncIndex { get; set; } = 0;
        /// <summary>
        /// 拔膜预对位坐标系翻转标识:0.不翻转 1.翻转
        /// </summary>
        public int L_ExcSTIsMirror { get; set; } = 0;

        public int L_ULDST_AcqIdx { get; set; } = 0;
        
        #endregion


        #endregion

        #region 远程端数据
        /// <summary>
        /// VisionPC RunMode:0,,Manual;1,Auto;
        /// </summary>
        public int R_VisionPC_RunMode { get; set; } = 0;

        /// <summary>
        /// CCD1控制 1-CH1 2-CH2
        /// </summary>
        public int R_CCD1ControlIndex { get; set; } = 0;
        /// <summary>
        /// CCD1控制移动数据
        /// </summary>
        public double R_CCD1Control_X { get; set; } = 0;
        public double R_CCD1Control_Y { get; set; } = 0;
        public double R_CCD1Control_Z { get; set; } = 0;

        public int R_CCD2ControlIndex { get; set; } = 0;
        public double R_CCD2Control_X { get; set; } = 0;
        public double R_CCD2Control_Y { get; set; } = 0;
        public double R_CCD2Control_Z { get; set; } = 0;
        /// <summary>
        /// CCD1检测结果
        /// </summary>
        public int R_CCD1_InspRet { get; set; } = 0;
        /// <summary>
        /// CCD2检测结果
        /// </summary>
        public int R_CCD2_InspRet { get; set; } = 0;










        public double R_EfemControl_X { get; set; } = 0;
        public double R_EfemControl_Y { get; set; } = 0;
        public double R_EfemControl_R { get; set; } = 0;

        public double R_ExcSTControl_X { get; set; } = 0;
        public double R_ExcSTControl_Y { get; set; } = 0;
        public double R_ExcSTControl_R { get; set; } = 0;

        public double R_SortSTControl_X { get; set; } = 0;
        public double R_SortSTControl_Y { get; set; } = 0;
        public double R_SortSTControl_R { get; set; } = 0;

        public double R_ULDSTControl_X { get; set; } = 0;
        public double R_ULDSTControl_Y { get; set; } = 0;
        public double R_ULDSTControl_R { get; set; } = 0;

        public double R_EfemOffset_X { get; set; } = 0;
        public double R_EfemOffset_Y { get; set; } = 0;
        public double R_EfemOffset_R { get; set; } = 0;

        public double R_SortSTFinalOffset_X { get; set; } = 0;
        public double R_SortSTFinalOffset_Y { get; set; } = 0;
        public double R_SortSTFinalOffset_R { get; set; } = 0;

        public double R_SortSTFinalForTR1_X { get; set; } = 0;
        public double R_SortSTFinalForTR1_Y { get; set; } = 0;
        public double R_SortSTFinalForTR1_R { get; set; } = 0;
        public double R_SortSTFinalForTR1_StageR { get; set; } = 0;

        public double R_SortSTFinalForTR2_X { get; set; } = 0;
        public double R_SortSTFinalForTR2_Y { get; set; } = 0;
        public double R_SortSTFinalForTR2_R { get; set; } = 0;
        public double R_SortSTFinalForTR2_StageR { get; set; } = 0;

        public double R_LaserSTOffset_X { get; set; } = 0;
        public double R_LaserSTOffset_Y { get; set; } = 0;
        public double R_LaserSTOffset_Z { get; set; } = 0;

        public double R_ULDSTFirstOffset_X { get; set; } = 0;
        public double R_ULDSTFirstOffset_Y { get; set; } = 0;
        public double R_ULDSTFirstOffset_R { get; set; } = 0;

        public double R_ULDSTFinalOffset_X { get; set; } = 0;
        public double R_ULDSTFinalOffset_Y { get; set; } = 0;
        public double R_ULDSTFinalOffset_R { get; set; } = 0;

        public double R_ULDTR_1_Offset_X { get; set; } = 0;
        public double R_ULDTR_1_Offset_Y { get; set; } = 0;
        public double R_ULDTR_1_Offset_R { get; set; } = 0;

        public double R_ULDTR_2_Offset_X { get; set; } = 0;
        public double R_ULDTR_2_Offset_Y { get; set; } = 0;
        public double R_ULDTR_2_Offset_R { get; set; } = 0;

        public int R_EfemAlignRet { get; set; } = 0;
        public int R_ExcSTReadCodeRet { get; set; } = 0;
        public int R_ExcSTInspRet { get; set; } = 0;
        public int R_SortSTFirstAlignRet { get; set; } = 0;
        public int R_SortSTFinalAlignRet { get; set; } = 0;
        public int R_DieAlignUpRet { get; set; } = 0;
        public int R_DieAlignFrontRet { get; set; } = 0;
        public int R_LaserCodeReadRet { get; set; } = 0;
        public int R_ULDTR_1_InspRet { get; set; } = 0;
        public int R_ULDTR_2_InspRet { get; set; } = 0;
        public int R_ULDTR_1_AlignRet { get; set; } = 0;
        public int R_ULDTR_2_AlignRet { get; set; } = 0;
        public int R_ULDSTFirstAlignRet { get; set; } = 0;
        public int R_ULDSTFinalAlignRet { get; set; } = 0;

        public string R_LaserCode { get; set; } = "";
        public string R_WaferID { get; set; } = "";

        public uint R_ExcSTMappingCount { get; set; } = 0;

        public ushort R_ConstantControl_Idx { get; set; } = 0;
        public double R_ConstantControl_Data { get; set; } = 0;

        #endregion

        public void UpdateRemote(ushort[] dataBuf)
        {
            R_CCD1ControlIndex= MemoryAccess.GetShortInt(dataBuf, 20);
            R_CCD1Control_X = MemoryAccess.GetShortInt(dataBuf, 22);
            R_CCD1Control_Y = MemoryAccess.GetShortInt(dataBuf, 24);
            R_CCD1Control_Z = MemoryAccess.GetShortInt(dataBuf, 26);


            R_CCD2ControlIndex = MemoryAccess.GetShortInt(dataBuf, 40);
            R_CCD1Control_X = MemoryAccess.GetShortInt(dataBuf, 42);
            R_CCD1Control_Y = MemoryAccess.GetShortInt(dataBuf, 44);
            R_CCD1Control_Z = MemoryAccess.GetShortInt(dataBuf, 46);

            R_CCD1_InspRet= MemoryAccess.GetShortInt(dataBuf, 60);
            R_CCD2_InspRet = MemoryAccess.GetShortInt(dataBuf, 65);

            R_VisionPC_RunMode = MemoryAccess.GetShortInt(dataBuf, 80);
         
        }

        public void UpdateLocal(ref ushort[] dataBuf)
        {
            MemoryAccess.SetString(ref dataBuf, L_RecipeID, 10, 20, " ");
            MemoryAccess.SetString(ref dataBuf, L_OperatorName, 20, 20, " ");
            MemoryAccess.SetString(ref dataBuf, L_LotNumber, 30, 20, " ");
            MemoryAccess.SetString(ref dataBuf, L_CCD1_InspStartTime, 40, 20, " ");
            MemoryAccess.SetString(ref dataBuf, L_CCD2_InspStartTime, 40, 20, " ");

            MemoryAccess.SetShortInt(ref dataBuf, L_StripRowTotal, 70);
            MemoryAccess.SetShortInt(ref dataBuf, L_StripColTotal, 71);
            MemoryAccess.SetString(ref dataBuf, L_LotId, 72, 20, " ");

            MemoryAccess.SetDoubleEx(ref dataBuf, L_DieLength, 82, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_DieWhith, 84, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_StepSize_X, 86, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_StepSize_Y, 88, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_CCD1_CurPos_X, 90, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_CCD1_CurPos_Y, 92, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_CCD1_CurPos_Z, 94, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_CCD2_CurPos_X, 96, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_CCD2_CurPos_Y, 98, 3);
            MemoryAccess.SetDoubleEx(ref dataBuf, L_CCD2_CurPos_Z, 100, 3);

            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_Photo_RowCount, 110);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_Photo_ColCount, 111);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_Photo_CurrentRow, 112);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_Photo_CurrentCol, 113);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_FuncIndex, 114);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_IsMirror, 115);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD1_InspSelect, 116);

            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_Photo_RowCount, 120);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_Photo_ColCount, 121);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_Photo_CurrentRow, 122);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_Photo_CurrentCol, 123);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_FuncIndex, 124);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_IsMirror, 125);
            MemoryAccess.SetShortInt(ref dataBuf, L_CCD2_InspSelect, 126);

            MemoryAccess.SetShortInt(ref dataBuf, L_MotionStatus, 130);
           
        }
    }
}
